<?php

namespace app\logic\queue\order_group;

use app\logic\single\group\GroupOrderSingle;
use think\facade\Log;
use think\queue\Job;

class Refund
{
    public function fire(Job $job, $data)
    {
        $rt = $this->doJob($data);
        if($rt){
            $job->delete();
            return true;
        }

        // 重试三次失败 todo...
        if($job->attempts() == 3){
            $job->delete();
            return false;
        }

        //执行失败10S后重试
        $job->release(10);


    }

    public function doJob($data)
    {
        Log::write($data,'order-group-refund');
        $order_id = $data['order_id']??0;
        if(!empty($order_id)){
            GroupOrderSingle::getInstance()->apply_refund($order_id);
        }


        return true;
    }
}